﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wjtour.Common;
using Hjp.FrameWork.Common;
using TongCheng.API.OpenAPI.Request;
using TongCheng.API.OpenAPI.Facade;

namespace Wjtour.Web.Front
{
    public partial class map : BasePage
    {
        private Wjtour.BLL.scene_bll _sceneBll = new BLL.scene_bll();
        private Wjtour.BLL.hotel_bll _hotelBll = new BLL.hotel_bll();
        private Wjtour.BLL.resturant_bll _restBll = new BLL.resturant_bll();
        private string type;
        private int id;
        protected string title;
        protected string tel;
        protected string address;
        protected string introduce;
        protected string img;

        protected void Page_Load(object sender, EventArgs e)
        {
            type = Request["type"];
            id = Utils.StrToInt(Request["id"], 0);

            if (id > 0)
            {
                if (type == "hotel")
                {
                    var hotel = _hotelBll.Load(id);
                    img = string.IsNullOrEmpty(hotel.img) ? "css/images/tmp13.png" : hotel.img;
                    title = hotel.hotelname;
                    tel = hotel.reservephone;
                    address = hotel.address.Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                    introduce = Utility.CutString(Utility.StripHtml(hotel.introduce).Replace(" ", ""), 45, true).Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                }
                if (type == "scene")
                {
                    var scene = _sceneBll.Load(id);
                    img = string.IsNullOrEmpty(scene.img) ? "css/images/tmp13.png" : scene.img;
                    title = scene.scenename;
                    tel = scene.contactphone;
                    address = scene.address.Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                    introduce = Utility.CutString(Utility.StripHtml(scene.introduce).Replace(" ", ""), 45, true).Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                }
                if (type == "rest")
                {
                    var rest = _restBll.Load(id);
                    img = string.IsNullOrEmpty(rest.img) ? "css/images/tmp13.png" : rest.img;
                    title = rest.resturantname;
                    tel = rest.contactphone;
                    address = rest.address.Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                    introduce = Utility.CutString(Utility.StripHtml(rest.introduce).Replace(" ", ""), 45, true).Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                }
                if (type == "hotelapi")
                {
                    GetHotelDetailRequest request = new GetHotelDetailRequest();
                    request.Body.clientIp = "172.0.0.1";
                    request.Body.hotelId = id;

                    var response = HotelFacade.GetHotelDetail(request);
                    var hotel = response.Body.hotelInfo;
                    if (hotel.extInfoOfImageList != null 
                        && hotel.extInfoOfImageList.sizeCodeList!=null
                        && hotel.extInfoOfImageList.sizeCodeList.Items.Count>0)
                    {
                       string url = hotel.extInfoOfImageList.sizeCodeList.Items[0].text;
                       img = hotel.extInfoOfImageList.imageBaseUrl + url;
                    }
                    title = hotel.hotelName;
                    tel = "";
                    address =(hotel.street+ hotel.streetAddr).Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                    introduce = Utility.CutString(Utility.StripHtml(hotel.intro).Replace(" ", ""), 45, true).Replace("\"", "").Replace("'", "").Replace("\r\n", "");

                }
                if (type == "sceneapi")
                {
                    GetSceneryDetailRequest request = new GetSceneryDetailRequest();
                    request.Body.ClientIp = "172.0.0.1";
                    request.Body.Cs = "1";
                    request.Body.SceneryId = id;

                    var response = SceneryFacade.GetSceneryDetail(request);
                    var scenery = response.Body.scenery;

                    GetSceneryListRequest request3 = new GetSceneryListRequest();
                    request3.Body.ClientIp = "172.0.0.1";
                    request3.Body.ProvinceId = 16;
                    request3.Body.CityId = 226;
                    request3.Body.Page = 1;
                    request3.Body.Cs = "1";
                    request3.Body.SortType = 0;
                    request3.Body.GradeId = "1,2,3,4,5";
                    request3.Body.PageSize = 100;

                    var response3 = SceneryFacade.GetSceneryList(request3);
                    var sl = response3.Body.sceneryList;
                    var list2 = response3.Body.sceneryList.Items;
                    for (int i = 0; i < list2.Count; i++)
                    {
                        if (list2[i].sceneryId == scenery.sceneryId)
                        {
                            scenery.imgPath = sl.ImgbaseURL + list2[i].imgPath;
                        }
                    }

                    img = scenery.imgPath;
                    title = scenery.sceneryName;
                    tel = "";
                    address = scenery.sceneryAddress.Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                    introduce = Utility.CutString(Utility.StripHtml(scenery.intro).Replace(" ", ""), 45, true).Replace("\"", "").Replace("'", "").Replace("\r\n", "");
                }
            }
        }
    }
}
